<div class="dialog-wrap" id="talentDialogContent">
    <form class="layui-form layui-user-from" action="">
        <div class="layui-row">
            <div class="layui-col-md8 layui-col-md-offset2">
                <div class="layui-row">
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="projectName"  lay-verify="required" lay-reqtext="项目名称不能为空" placeholder="" autocomplete="off" class="layui-input" value="">
                            </div>
                        </div>
                    </div>
                    <!--此处从后台获取-->
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">客户编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="clientName"  lay-verify="required" lay-reqtext="客户编号不能为空"  class="layui-input layui-bg-gray" disabled placeholder="" autocomplete="off" class="layui-input" value="222">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">客户名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="clientName"  lay-verify="required" lay-reqtext="客户名称不能为空"  class="layui-input layui-bg-gray" disabled placeholder="" autocomplete="off" class="layui-input" value="1111">
                            </div>
                        </div>
                    </div>
                    <!--此处从后台获取-->
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">客户联系人编号</label>
                            <div class="layui-input-block">
                                <select name="clientContactId" lay-verify="required" lay-reqtext="联系人编号不能为空" lay-search>
                                    <option value="">请选择</option>
                                    <option value="0">C001</option>
                                    <option value="1" selected="">C002</option>
                                    <option value="2">C003</option>
                                    <option value="3">C004</option>
                                    <option value="4">C005</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否保密项目</label>
                            <div class="layui-input-block">
                                <input type="radio" name="isPrivate" value="1" title="是" checked="">
                                <input type="radio" name="isPrivate" value="2" title="否">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">开始日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="startDate"  id="startDateId" placeholder=""  lay-verify="required" lay-reqtext="开始日期不能为空" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">结束日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="endDate" id="endDateId"  placeholder="" lay-verify="required" lay-reqtext="结束日期不能为空" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">负责人</label>
                            <div class="layui-input-block">
                                <input type="text" name="ownerBy" id="ownerBy" class="layui-input" style="position:absolute;z-index:2;width:80%;" lay-verify="required" value="111" onkeyup="search()" autocomplete="off">
                                <select id="ownerBySelect" lay-filter="ownerBySelect" autocomplete="off" placeholder="负责人" lay-verify="required" class="layui-select" lay-search>
                                    <option value="111">请选择</option>
                                    <option value="111">111</option>
                                    <option value="222">222</option>
                                    <option value="333">333</option>
                                    <option value="444">444</option>
                                    <option value="555">555</option>
                                </select>

                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                                <a class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="operationSaveBtn">保存</a>
                                <a class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="operationSubmitBtn">提交</a>
                                <button type="reset" class="layui-btn  layui-btn-sm layui-btn-primary">重置</button>
                                <input type="hidden" name="projectId" id="hiddenVal" value=""><!--编辑时用到-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form','laydate','utils'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.jquery,
            utils = layui.utils;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        /**a
         * 开始时间
         **/
        laydate.render({
            elem: '#startDateId',
            trigger: 'click'
        });

        /**
         * 结束时间
         **/
        laydate.render({
            elem: '#endDateId',
            trigger: 'click',
        });


        form.on('select(ownerBySelect)', function (data) {   //选择移交单位 赋值给input框
            $("#ownerBy").val(data.value);
            $("#ownerBySelect").next().find("dl").css({ "display": "none" });
            form.render();
        });

        window.search = function () {
            var value = $("#ownerBy").val();
            $("#ownerBySelect").val(value);
            form.render();
            $("#ownerBySelect").next().find("dl").css({ "display": "block" });
            var dl = $("#ownerBySelect").next().find("dl").children();
            var j = -1;
            for (var i = 0; i < dl.length; i++) {
                if (dl[i].innerHTML.indexOf(value) <= -1) {
                    dl[i].style.display = "none";
                    j++;
                }
                if (j == dl.length-1) {
                    $("#ownerBySelect").next().find("dl").css({ "display": "none" });
                }
            }

        }



        //监听保存
        form.on('submit(operationSaveBtn)', function (data) {
            data.field.id = 2;
            data.field.operation = 1;//保存
            /*var index = layer.alert(JSON.stringify(data.field), {
               title: '最终的提交信息'
            });*/
            _subUrl = '/api/project/edit.json';
            utils.Ajax({
                url: _subUrl,
                dataType: 'json',
                contentType:"application/json;charset=utf-8",
                type: 'post',
                data: {data:JSON.stringify(data.field)},
                success: function (response) {
                    if (response.code == 200) {
                        parent.layer.msg(res.message, {
                            time: 1000, //1s后自动关闭
                        });
                        // 关闭弹出层
                        layer.close(parentIndex);
                    } else {
                        parent.layer.msg(res.message,{
                            time: 1000, //1s后自动关闭
                        });
                    }
                },
                error: function (err) {
                    parent.layer.msg(err.message,{
                        time: 1000, //1s后自动关闭
                    });
                }
            })
        }, function () {
            // 关闭弹出层
            layer.close(parentIndex);

        });



        //监听提交
        form.on('submit(operationSubmitBtn)', function (data) {
            data.field.id = 2;
            data.field.operation = 2;//提交
            /*var index = layer.alert(JSON.stringify(data.field), {
               title: '最终的提交信息'
            });*/
            if(data.field.isPrivate == 2){
                parent.layer.msg('必须选择保密',{
                    time: 1000, //1s后自动关闭
                });
                return false;
            }
            _subUrl = '/api/project/edit.json';
            var _headers = {"token": sessionStorage.getItem("token")};
            $.ajax({
                url: _subUrl,
                dataType: 'json',
                contentType:"application/json;charset=utf-8",
                type: 'post',
                data: {data:JSON.stringify(data.field)},
                success: function (response) {
                    if (response.code == 200 && res.message == '保存成功') {
                        parent.layer.msg(res.message, {
                            time: 1000, //1s后自动关闭
                        });
                        // 关闭弹出层
                        layer.close(parentIndex);
                    } else {
                        parent.layer.msg(res.message,{
                            time: 1000, //1s后自动关闭
                        });
                        return false;
                    }
                }
            })
        }, function () {
            // 关闭弹出层
            layer.close(parentIndex);

        });

        return false;
        });
</script>
</body>
</html>
